import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

///class DatePickerUtil {
Future<dynamic> showCustomerDatePicker<T>(
    {required BuildContext context,
    DateTime? initDate,
    required ValueChanged<DateTime> onDateSelected,
    CupertinoDatePickerMode? selectModel}) {
  var result = initDate ?? DateTime.now();
  return showCupertinoModalPopup(
      context: context,
      builder: (context) {
        return Container(
          height: 240,
          color: Theme.of(context).primaryColor,
          child: Column(
            children: [
              Padding(
                padding:
                    const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  mainAxisSize: MainAxisSize.max,
                  children: [
                    GestureDetector(
                      onTap: () => Navigator.pop(context),
                      child: Text(
                        '取消',
                        style: TextStyle(
                            color: Theme.of(context).splashColor, fontSize: 12),
                      ),
                    ),
                    GestureDetector(
                      onTap: () {
                        onDateSelected(result);
                        Navigator.pop(context);
                      },
                      child: Text(
                        '确定',
                        style: TextStyle(
                            color: Theme.of(context).toggleableActiveColor,
                            fontSize: 12),
                      ),
                    )
                  ],
                ),
              ),
              // SizedBox(
              //   height: 200,
              //   child: CalendarDatePicker(
              //     firstDate: DateTime.parse("1900-01-01"),
              //     lastDate: DateTime.now(),
              //     initialDate: DateTime.now(),
              //     onDateChanged: (DateTime value) {
              //       result = value;
              //     },
              //   ),
              // )
              SizedBox(
                height: 200,
                child: CupertinoDatePicker(
                  // backgroundColor: Colors.white,
                  //minuteInterval: 10,
                  use24hFormat: true,
                  mode: selectModel ?? CupertinoDatePickerMode.dateAndTime,
                  onDateTimeChanged: (date) {
                    // logger.d('date:$date');
                    result = date;
                  },
                  initialDateTime: initDate ?? DateTime.now(),
                ),
              )
            ],
          ),
        );
      });
}

//}
